package com.cloud.sms.interceptor;

import com.cloud.commons.exception.ParamsValidateException;
import com.cloud.commons.utils.ParamCheckUtils;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;


/**
 * @Description:参数效验拦截器 Author    Version		Date		Changes
 * zhuangjianfa 1.0  2018年2月1日 Created
 */
@Order(1000)
@Aspect
@Component
public class ValidateParameterAspectAdvice {

    private Logger logger = LoggerFactory.getLogger(ValidateParameterAspectAdvice.class);
    
    @Before("execution(* com.cloud.sms.manager.impl.*.*(..))")
    public void before(JoinPoint pjd) {
        Object[] args = pjd.getArgs();
        if (args.length > 0) {
            Object oneParam = args[0];
            String check = ParamCheckUtils.checkParam(oneParam);
            if (check != null) {
                logger.error("ParamsValidateException , class={}, method={}, msg={}", pjd.getTarget().getClass().getSimpleName(), pjd.getSignature().getName(), check);
                throw new ParamsValidateException(1000, check);
            }
        }
    }
}
